import { createSlice } from "@reduxjs/toolkit";
import type { UserInfoType } from "../../types";

export const userSlice = createSlice({
  name: "userSlice",
  initialState: {
    accessToken: "",
    refreshToken: "",
    userInfo: {} as UserInfoType,
  },
  reducers: {
    loginSuccess(state, action) {
      state.accessToken = action.payload.accessToken;
      state.refreshToken = action.payload.refreshToken;
      state.userInfo = action.payload.userInfo;
    },
    quit(state) {
      state.accessToken = "";
      state.refreshToken = "";
      state.userInfo = {} as UserInfoType;
    },
  },
});

export const { loginSuccess, quit } = userSlice.actions;
